package com.mymaxis.utils;

import com.checkfree.isolutions.customer.persist.Account;
import com.checkfree.isolutions.customer.persist.AccountHomeImpl;
import com.checkfree.isolutions.customer.persist.Merchant;
import com.checkfree.isolutions.customer.persist.MerchantHomeImpl;
import com.checkfree.isolutions.persist.PersistServer;
import com.mymaxis.ebppx.EbppxConstants;

public class AccountInfo {

	private static String merchant = EbppxConstants.MERCHANT;
	
	public boolean isAccountExist(String strAccNo) {
		
		boolean status = false;
		
		PersistServer.activate(merchant);
		System.out.println("Activating Persistent Server.....");
		
		PersistServer.beginTransaction();
		System.out.println("Starting the transaction.....");
		
		try{
			
			Merchant cfiMerchant = MerchantHomeImpl.singleton().findByName(merchant);
			System.out.println("cfiMerchant:" + cfiMerchant);
			Account account = AccountHomeImpl.singleton().findByExternalKeyAndMerchant(strAccNo, cfiMerchant);
			System.out.println("account:" + account);
			
			
			if (account != null) {
				
				status = true;
				
			}
			
			PersistServer.commitTransaction();
			System.out.println("Stoping the transaction.....");
			
		}catch(Exception e) {
			e.printStackTrace();
		} catch (Throwable t) {
			t.printStackTrace();
		}finally {
			if (PersistServer.transactionIsActive()){
				try {
					PersistServer.rollbackTransaction();
				}catch (Exception e) {
				}
			}
			PersistServer.deactivate(); //clean up with deactivate
			System.out.println("Deactivate the transaction.....");
		}
		
		return status;
		
	}
	
}
